package com.ruoyi.activity.service.impl;

import java.util.List;

import com.ruoyi.activity.domain.Works;
import com.ruoyi.activity.req.EvaluateListReq;
import com.ruoyi.activity.req.ReviewWorkReq;
import com.ruoyi.activity.resp.EvaluateResp;
import com.ruoyi.activity.service.IWorksService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.activity.mapper.EvaluateMapper;
import com.ruoyi.activity.domain.Evaluate;
import com.ruoyi.activity.service.IEvaluateService;

/**
 * 评价管理Service业务层处理
 *
 * @author wxc
 * @date 2024-05-30
 */
@Service
public class EvaluateServiceImpl implements IEvaluateService
{
    @Autowired
    private EvaluateMapper evaluateMapper;
    @Autowired
    private IWorksService worksService;

    /**
     * 查询评价管理
     *
     * @param id 评价管理主键
     * @return 评价管理
     */
    @Override
    public Evaluate selectEvaluateById(Long id)
    {
        return evaluateMapper.selectEvaluateById(id);
    }

    /**
     * 查询评价管理列表
     *
     * @param evaluate 评价管理
     * @return 评价管理
     */
    @Override
    public List<EvaluateResp> selectEvaluateList(EvaluateListReq evaluate)
    {
        List<EvaluateResp> evaluates = evaluateMapper.selectEvaluateList(evaluate);
        System.out.println(evaluates);
        return evaluates;
    }

    /**
     * 新增评价管理
     *
     * @param evaluate 评价管理
     * @return 结果
     */
    @Override
    public int insertEvaluate(Evaluate evaluate)
    {
        evaluate.setCreateTime(DateUtils.getNowDate());
        return evaluateMapper.insertEvaluate(evaluate);
    }

    /**
     * 修改评价管理
     *
     * @param evaluate 评价管理
     * @return 结果
     */
    @Override
    public int updateEvaluate(Evaluate evaluate)
    {
        return evaluateMapper.updateEvaluate(evaluate);
    }

    /**
     * 批量删除评价管理
     *
     * @param ids 需要删除的评价管理主键
     * @return 结果
     */
    @Override
    public int deleteEvaluateByIds(Long[] ids)
    {
        return evaluateMapper.deleteEvaluateByIds(ids);
    }

    /**
     * 删除评价管理信息
     *
     * @param id 评价管理主键
     * @return 结果
     */
    @Override
    public int deleteEvaluateById(Long id)
    {
        return evaluateMapper.deleteEvaluateById(id);
    }

    @Override
    public int review(ReviewWorkReq reviewWorkReq) {

        Works works = worksService.review(reviewWorkReq);
        Evaluate evaluate = new Evaluate();
        evaluate.setCreateTime(DateUtils.getNowDate());
        evaluate.setJudgeName(reviewWorkReq.getJudgeName());
        evaluate.setScore(reviewWorkReq.getScore());
        evaluate.setWorksId(reviewWorkReq.getId());
        evaluate.setSchool(works.getSchool());
        int i = evaluateMapper.insertEvaluate(evaluate);
        return i;
    }
}
